/**
 * Renders the main menu
 * @param int activeMenuItem = the number of the active menu item
 * @param int menuItemsCount = the total number of menu items
 * @param char* menuItems[] = array of pointers to char arrays
 */
void renderMenu(int activeMenuItem, int menuItemsCount, char* menuItems[]) {
	// Colors
	Color defaultTextColor; defaultTextColor.r = 1.0f; defaultTextColor.g = 0.0f; defaultTextColor.b = 0.0f;
	Color activeTextColor; activeTextColor.r = 1.0f; activeTextColor.g = 1.0f; activeTextColor.b = 1.0f;
	
	
	// Calculate center position in window
	int windowWidth;
	int windowHeight;
	
	glfwGetWindowSize(&windowWidth, &windowHeight);
	
	// find center position
	int centerWidth = floor(windowWidth / 2.0f);
	int centerHeight = floor(windowHeight / 2.0f);
	int offsetWidth = 100;
	int offsetHeight = 100;
	
	if (gamePlaying == GL_TRUE) {
		if (0 == activeMenuItem) 
			printTextOnScreen(150,170,10, menuItems[0], defaultTextColor);
		else 
			printTextOnScreen(150,170,10, menuItems[0], activeTextColor);
	}
	
	int i;
	for (i=1; i < menuItemsCount; i++) {
		if (i == activeMenuItem) 
			// printTextOnScreen(centerWidth -offsetWidth,centerHeight + i*20 -offsetHeight,10, menuItems[i], defaultTextColor);	
			printTextOnScreen(150,200 + (i-1)*20,10, menuItems[i], defaultTextColor);					
		else 
			// printTextOnScreen(centerWidth -offsetWidth,centerHeight + i*20 -offsetHeight,10, menuItems[i], activeTextColor);
			printTextOnScreen(150,200 + (i-1)*20,10, menuItems[i], activeTextColor);
	}

}

/**
 * Renders all information for the active menu item
 * @param int activeMenuItem = the number of the active menu item
 * @param int menuItemsCount = the total number of menu items 
 */
void renderMenuItemContent(int activeMenuItem) {
	Color activeTextColor; activeTextColor.r = 1.0f; activeTextColor.g = 1.0f; activeTextColor.b = 1.0f;
	
	char msg[15][30];
	int textRows = 1;
	
	switch (activeMenuItem) {
		case 0: // RESUME
			strcpy(msg[0],"Resume your fucking game");
			break;
		case 1: // PLAY
			strcpy(msg[0],"Play the fucking game");
			break;
		case 2: // ABOUT
			textRows = 7;	
			strcpy(msg[0],"Developed by:");
			strcpy(msg[1],"Bjorn Gotestrand");
			strcpy(msg[2],"Erik Hammarlund");
			strcpy(msg[3],"Sebastian Rauhala");
			strcpy(msg[4],"Jonas Strandstedt");
			strcpy(msg[5],"Christoffer Svahn");			
			strcpy(msg[6],"Philip Zanderholm");
			break;
		case 3: // CONTROLS
			textRows = 11;
			strcpy(msg[0],"PLAYER 1");
			strcpy(msg[1],"Forward:  'W'");
			strcpy(msg[2],"Backward: 'S'");
			strcpy(msg[3],"Left:     'A'");
			strcpy(msg[4],"Right:    'D'");			
			strcpy(msg[5],"");
			strcpy(msg[6],"PLAYER 2");
			strcpy(msg[7],"Forward:  'UP'");
			strcpy(msg[8],"Backward: 'DOWN'");
			strcpy(msg[9],"Left:     'LEFT'");
			strcpy(msg[10],"Right:    'RIGHT'");						
			break;
		case 4: // SETTINGS
			strcpy(msg[0],"No settings available yet. ");						
			break;
		case 5: // EXIT
			strcpy(msg[0],"Goodbye & thanks for playing.");

		default:
			break;
	}
	
	// Print all rows of text
	while (textRows > 0) {
		printTextOnScreen(350,200 + (textRows-1)*20 ,8, msg[textRows-1], activeTextColor);		
		textRows--;
	}
}

/**
 * Handler for menu interaction
 * @param int activeMenuItem = the number of the active menu item
 * @param int menuItemsCount = the total number of menu items 
 */
void menuInteractions(int activeMenuItem, int menuItemsCount) {
	// MOVE INTERACTIONS HERE
}


/**
 * Renders the menu background
 * @param int activeMenuItem = the number of the active menu item
 * @param int textures[] = array of allocated textures references.  
 */
void renderMenuBackground() {
	
	// Windows size
	int width, height;
	glfwGetWindowSize( &width, &height );
	
	// Stuff to make ortohonal projection.
	glMatrixMode (GL_PROJECTION);
	glLoadIdentity();
	glMatrixMode (GL_MODELVIEW);
	glLoadIdentity();

	// Load texture from file, and build all mipmap levels			
	glOrtho(0.0, (float) width, (float) height, 0.0, -30.0, 30.0);
	
	// Create Quad and add texture
	glEnable(GL_BLEND);	
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	glBegin(GL_QUADS);	
	glColor4f(0,0,0,0.65);			
	
	int top = 100;
	int bottom = 500;
	int left = 100;
	int right = 700;
	
	glVertex3f(left,top,-1);		
	glVertex3f(left,bottom,-1);
	glVertex3f(right,bottom,-1);
	glVertex3f(right,top,-1);
	glEnd();
	
	glDisable(GL_BLEND);
//	glBindTexture(GL_TEXTURE_2D,0);
}